草庐IT

Android PNG 到位图 --- SkImageDecoder::Factory 返回 null

全部标签

ruby-on-rails - 使用 Rspec、Devise 和 Factory Girl 测试用户模型

我认为我的用户工厂正在构建时出现问题。我收到一条错误消息,提示密码不能为空,但它在我的factories.rb中明确设置。有人看到我可能遗漏的任何东西吗?或者规范失败的原因?我为我的其他模型之一做了非常相似的事情,而且似乎成功了。我不确定错误是否是由设计引起的。Rspec错误UsershouldcreateanewinstanceofausergivenvalidattributesFailure/Error:User.create!(@user.attributes)ActiveRecord::RecordInvalid:Validationfailed:Passwordcan'tb

ruby-on-rails - 如果我调用 Factory.build 以使我的 Controller 测试快速,我怎样才能让 Factory Girl 永远不会访问数据库?

我正在寻求使我的Rails测试更快。我只有520个测试,但它们在bash中运行需要62秒,在Rubymine中运行需要82秒。作为典型Controller测试的示例,我使用此代码以@user身份登录并在CommentsController中为我的RSpecController测试创建基本的@comment:before(:each)do@user=Factory.create(:user)sign_in@user@comment=Factory.create(:comment)end您可能会意识到...这很慢。它构建了一个@user,但也为该用户构建了关联。@comment也是如此。所

ruby - 我如何打破 map /收集并返回到那时收集的任何东西?

我正在用代码重写这个问题:many=1000#Anexpensivemethod.##Itreturnssomedataornilifnoresultisavailable.expensive_method=lambdadorand(5)==0?nil:"foo"end#Now,let'scollectsomedataandstopcollectingwhennomoredatais#available.#Thisisconcisebutdoesn'twork.collection=many.times.mapdoexpensive_method.call||breakendputsc

ruby - 返回 ruby​​ 中字符串中所有出现的字符的索引

我正在尝试使用Ruby将索引返回到字符串中所有出现的特定字符。示例字符串是"a#asg#sdfg#d##"并且在搜索时预期返回是[1,5,10,12,13]#个字符。以下代码可以完成这项工作,但必须有更简单的方法吗?defoccurances(line)index=0all_index=[]line.each_bytedo|x|ifx=='#'[0]thenall_index 最佳答案 s="a#asg#sdfg#d##"a=(0...s.length).find_all{|i|s[i,1]=='#'}

ruby - 为什么.all?在空数组上返回 true?

我想使用Ruby评估数组中的所有项,如果它们都通过条件测试则返回true。我可以使用例如array.all?{|值|值==2}所以:>array=[2,2]>array.all?{|value|value==2}=>true>array=[2,3]>array.all?{|value|value==2}=>false太棒了!但是,为什么一个空数组可以通过这个测试呢?>array=[]>array.all?{|value|value==2}=>true这不应该返回false吗?如果我需要它返回false,我应该如何修改方法? 最佳答案

ruby-on-rails - 为什么 Ruby "script/generate"返回 "No such file or directory"?

我在使用script/generate时遇到问题。我正在关注treebasednavigation教程,它说使用script/plugininstallgit://github.com/rails/acts_as_tree.git或script/generatenifty_layout。我不断得到:Nosuchfileordirectory--script/plugin我试过这些变体:script/generatenifty_layoutrailsgeneratenifty_layoutrubyscript/generatenifty_layoutrubygeneratenifty_l

ruby-on-rails - 测试时我应该在 Factory girl 中 stub 模型还是在规范文件中 stub ?

几乎我遇到的每一个规范文件我最终都会写这样的东西:before:eachdo@cimg=Factory.build:cimg_valid@cimg.stub(:validate_img).and_returntrue@cimg.stub(:validate_img_url).and_returntrue@cimg.stub(:save_images).and_returntrue@cimg.stub(:process_image).and_returntrue@cimg.stub(:img).and_returntrueend我的意思是,我从Factory.build获得的模型是完全有

ruby-on-rails - 如何引发 ActiveRecord::Rollback 异常并一起返回值?

我有一个使用acts_as_nested_set分支的模型,并且我向模型添加了一个方法来保存模型并将节点移动到一个事务中的集合中。此方法调用验证方法以确保移动有效,它返回true或false。如果验证失败,我希望我的保存方法引发ActiveRecord::Rollback以回滚事务,但也向调用者返回false。我的模型是这样的:classCategory:destroy,:scope=>:journaldefsave_with_place_in_set(parent_id)Category.transactiondoreturnfalseif!save_without_place_in

ruby - 从 fork 进程返回数据

如果我这样做Process.forkdoxend我怎么知道x返回了什么(例如true/fase/string)?(写入文件/数据库不是一种选择...) 最佳答案 我们实际上只需要在Railsisolationtesting中处理这个问题.我发布了一些onmyblog.基本上,您要做的是在父项和子项中打开一个管道,然后让子项写入管道。这是在子进程中运行block内容并取回结果的简单方法:defdo_in_childread,write=IO.pipepid=forkdoread.closeresult=yieldMarshal.dum

ruby-on-rails - 对象.有效?返回 false 但 object.errors.full_messages 为空

我对无法保存的对象感到困惑,简化模型是classSubscription"User",:foreign_key=>"user_id"has_many:transactions,:class_name=>"SubscriptionTransaction"validates_presence_of:first_name,:message=>"nepeutêtrevide"validates_presence_of:last_name,:message=>"nepeutêtrevide"validates_presence_of:card_number,:message=>"nepeutêt